const schemaJoi = require('./util/schemaJoi.js');
const Joi = require('joi');
const service = require('./service/service.js');

// 加购
exports.addCartOder = async (context) => {
	const {cloud, data, mixNick, userNick } = context
	try {
		const params = {
			nickName: userNick || '没授权',
			mixnick: mixNick,
			...data
		}
		const schema = Joi.object().keys({
      // id: Joi.Number().required(),
			cart_data: Joi.string().required(),
			sample_data: Joi.string().required(),
			nickName: Joi.string().required(),
			mixnick: Joi.string().required(),
    });
    await schemaJoi(schema, params);
		return await service.addCart(params, cloud);
	} catch (e) {
		return { errCode: 1111, msg: '铺捉到错误' + e };
	}
};


